#pragma once

#include "qcontrol.h"
#include "qarray.h"

using namespace micro::utils;

const   int  TS_MAXTAB		= 0;
const   int  TS_EQUALTAB	= 1;

const	int  MAX_TAB_SIZE	= 180; //PIXELS


namespace micro
{
namespace gui
{

class QTab
{

public:
    QString	 title;
    QPanel * pChild;
    QRect	 rect;
    UINT	 id;

public:
    QTab()
    {
        pChild = nullptr;
        id = 0;
    }
    ~QTab()	{	}
    QTab( QPanel * pwin, const QString & cap = _T( "" ),  UINT idd  = 0 )
    {
        pChild	= pwin;

        if ( cap.IsEmpty() )
            pChild->GetText( title  );
        else
            title = cap ;

        id = idd;
    }

    void SetCaption( const QString & str )
    {
        title = str;
    }

};

class QTabContainer: public QControl
{

protected:

    int				m_currentTab;
    int				m_style;

    ///colors
    QCOLOR			m_bkColor;



    //QSize			m_sizeImag;
    QFont			m_font;//header font


    QPen pen;

    QObArray<QTab>	m_tabList;
    QTheme			m_theme;



public:
    QTabContainer( void );
    virtual ~QTabContainer( void );



    virtual bool OnPreCreate( CREATESTRUCT & cs );
    virtual bool Create( QWindow * parent, int id = 0, UINT style = 0 );

    virtual bool OnSize( int type, int cx, int cy );
    virtual bool OnEraseBackground( QGraphics * );
    virtual bool OnPaint( QGraphics * pdc );

    virtual bool OnSetFocus( HWND hwnd );

    virtual bool OnLButtonDown( UINT flags, QPoint & point );
    virtual bool OnLButtonDblClk( UINT flags, QPoint & point );



    virtual bool OnMouseLeave();
    //virtual bool OnMouseHover(UINT nFlags, QPoint& point);
    virtual bool OnMouseMove( UINT flags, QPoint & point );


protected:
    //signals
    virtual void OnTabChange() {}


protected:
    void    DrawTabs( QGraphics * pdc, int iSel = -1 );
    void	AdjustRect( BOOL flag, QRect & rect );
    void    RecalcLayout();


public:
    ///colors
    void	SetBkColor( QCOLOR c );
    void	SetStyle( UINT style );


    ///insert after current tab
    bool    InsertTab( QPanel * pChild, QString pMsg = _T( "" ), UINT id  = 0 );
    bool	AddTab( QPanel * pChild, QString lpMsg = _T( "" ), UINT id  = 0 );

    void    RemoveTab( int nrTab );
    void	RemoveTab( QPanel  * p );

    void	SetActiveTabByID( int unicid );
    void	SetActiveTab( int tab );
    int		GetCurrentTab();
    int		GetTabCount();

    void    MoveNextTab( bool next = true );

    QWindow * GetCurrentWindow();
    QWindow * GetChildWindow( int tab );

    bool	Find( QPanel * p );



};



}
}//micro